import os
import numpy as np
import h5py
import glob
import cv2

input_dir = "basement_0001a/"
output_dir = "basement_0001a_im/"

for filepath in glob.glob(os.path.join(input_dir, '*.h5')):
  print(filepath)
  # filename = filepath.split("/")[2].split(".")[0]
  filename = filepath.split("/")[1].split(".")[0]
  h5f = h5py.File(filepath, "r")
  rgb = np.array(h5f['rgb'])
  rgb = np.transpose(rgb, (1, 2, 0))
  depth = np.array(h5f['depth'])

  print(rgb.shape)
  cv2.imwrite(output_dir + filename + "_rgb.jpg",rgb)
  cv2.imwrite(output_dir + filename + "_depth.jpg",depth)